home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 376-400 / disk_376 / toollibrary / src / library_demo.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  233 lines

  1.  #include <exec/types.h>
  2.  #include <exec/memory.h>
  3.  #include <intuition/intuitionbase.h>
  4.  #include <proto/exec.h>
  5.  #include <proto/dos.h>
  6.  #include <proto/intuition.h>
  7.  #include <proto/graphics.h>
  8.  #include <proto/tool.h>
  9.  #include <string.h>
  10.  #include <stdlib.h>
  11.  #include <stdio.h>
  12.  
  13.  VOID main();
  14.  
  15.  struct Library *ToolBase;
  16.  struct IntuitionBase *IntuitionBase;
  17.  struct GfxBase  *GfxBase;
  18.  
  19.  char ja[]="JA !";
  20.  char nein[]="NE !!";
  21.  char body1[]="Sind Sie fertig ?";
  22.  char body2[]="Wirklich ?";
  23.  char for_check[]="1+2+3+4-(a-34+5)";
  24.  char string[50];
  25.  char string1[50];
  26.  char Zahl_string[]="-1.3467";
  27.  
  28.  SHORT paare3[]=
  29.   {
  30.    0,0,0,9,33,9,33,0,0,0
  31.   };
  32.  
  33.  struct Border Rand1 =
  34.   {
  35.    -1,-1,3,2,JAM2,5,paare3,0
  36.   };
  37.  
  38.  struct IntuiText Texte=
  39.   {
  40.    3,2,JAM2,0,0,0," OK ",0
  41.   };
  42.  
  43.  /* Definitionen für Gadgets */
  44.  
  45.  struct Gadget G=
  46.   {
  47.    NULL    ,100,20,32,8,GADGHCOMP,RELVERIFY|GADGIMMEDIATE,BOOLGADGET,(APTR)&Rand1,0,&Texte,NULL,NULL,4,0
  48.   };
  49.  
  50.  
  51.  
  52.  struct NewWindow Fenster=
  53.   {
  54.    10,10,520,130,0,1,CLOSEWINDOW|GADGETDOWN,WINDOWCLOSE,&G,0,"TestWindow",
  55.    0,0,0,0,0,0,WBENCHSCREEN
  56.   };
  57.  
  58.  
  59.  VOID main()
  60.   {
  61.    struct Window *Window;
  62.    struct RastPort *RastPort;
  63.    struct info msgInfo;
  64.    struct Block *Start;
  65.    APTR Konstanten;
  66.    
  67.    
  68.    long a,ENDE=1;
  69.    DOUBLE Zahl=1.2345677;
  70.    DOUBLE Zahl1=10346.2457;
  71.    
  72.    IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0);
  73.    if(!IntuitionBase)return;
  74.    GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0);
  75.    if(!GfxBase)
  76.     {
  77.      CloseLibrary((struct Library *)IntuitionBase);
  78.      return;
  79.     }
  80.    
  81.    
  82.    ToolBase=OpenLibrary("tool.library",0);
  83.    if(!ToolBase)
  84.     {
  85.      CloseLibrary((struct Library *)IntuitionBase);
  86.      CloseLibrary((struct Library *)GfxBase);
  87.      return;
  88.     }
  89.    
  90.    Window=OpenWindow(&Fenster);
  91.    if(!Window)goto ende;
  92.    printf("Fenster offen\n");
  93.    Delay(20);
  94.    RastPort=Window->RPort;
  95.    
  96.    a=request(ja,nein,body1);
  97.    printf("\n\nIhre Antwort : %ld\n",a);
  98.    
  99.    /* Fast die gleiche Funktion, nur kann hier noch das Fenster angegeben werden */
  100.    a=NewRequest(Window,ja,nein,body2);
  101.    printf("Ihre Antwort : %ld\n",a);
  102.    
  103.    left(string,body1,3);
  104.    printf(" >%s< -> >%s<\n",body1,string);
  105.    
  106.    right(string,body1,4);
  107.    printf(" >%s< -> >%s<\n",body1,string);
  108.    
  109.    mid(string,body1,5,4);
  110.    printf(" >%s< -> >%s<\n",body1,string);
  111.    
  112.    UmwFtoS(string ,&Zahl ,4);
  113.    UmwFtoS(string1,&Zahl1,3);
  114.    printf("Aus >%6.3lf< wird >%s<\n",Zahl ,string );
  115.    printf("Aus >%6.3lf< wird >%s<\n",Zahl1,string1);
  116.    
  117.    UmwStoF(&Zahl,Zahl_string);
  118.    printf("Aus >%s< wird >%6.3lf<\n",Zahl_string,Zahl);
  119.    
  120.    Fak(&Zahl,5);
  121.    printf("Fakultät von 5 ist : %6.3lf\n",Zahl);
  122.    NuK(&Zahl,49,6);
  123.    printf("49 über 6 ist : %6.3lf\n",Zahl);
  124.    
  125.    a=check('+','-',0,strlen(for_check),for_check);
  126.    printf("Erstes + oder - in >%s< bei : %ld\n",for_check,a);
  127.    
  128.    a=checkback('-','-',0,strlen(for_check),for_check);
  129.    printf("Letztes - in >%s< bei : %ld\n",for_check,a);
  130.    
  131.    a=AnzahlKlammern(for_check);
  132.    printf("Unpaarige Klammern: %ld\n",a);
  133.    
  134.    /* Ein bischen malen... */
  135.    for(a=10;a<=500;a+=50)
  136.     {
  137.      Box(RastPort,a,40,a+30,70);
  138.     }
  139.    
  140.    /* Für Flood vorbereiten */
  141.    if(PrepareTmpRas(RastPort))
  142.     {
  143.      for(a=10;a<=500;a+=50)
  144.       {
  145.        Flood(RastPort,1,a+1,41);
  146.       }
  147.      Delay(50);
  148.     }
  149.    /* Kann sein, daß der Blitter hier noch am arbeiten ist, daher lösche ich */
  150.    /* TmpRas erst später                                                     */
  151.    
  152.    Print(RastPort,"Dies ist ein Text",2,70,20);
  153.    Center(Window,"Dies ist ein Text",1,30);
  154.    
  155.    for(a=0;a<=3;a++)
  156.     {
  157.      Gadget_Off(&G,Window);
  158.      printf("aus\n");
  159.      Delay(30);
  160.      Gadget_On(&G,Window);
  161.      printf("ein\n");
  162.      Delay(30);
  163.     }
  164.    /* Hier sollte der Blitter eigentlich fertig sein */
  165.    ClearTmpRas(RastPort);
  166.    SetAPen(RastPort,0);
  167.    RectFill(RastPort,5,50,500,110);
  168.    SetAPen(RastPort,2);
  169.    
  170.    
  171.    if(a=PrepareArea(RastPort,100))
  172.     {
  173.      AreaMove(RastPort,110,30);
  174.      AreaDraw(RastPort,130,100);
  175.      AreaDraw(RastPort,105,50);
  176.      AreaEnd(RastPort);
  177.      Delay(50);
  178.      ClearArea(RastPort);
  179.     }
  180.    
  181.    /* Ein wenig rechnen */
  182.    strcpy(string,"sin(x)+a");
  183.    Konstanten=Init_Konst();
  184.    Zahl=1.0;
  185.    Set_Konst_P(Konstanten,1,&Zahl); /* a auf 1.0 setzten */
  186.    
  187.    Start=Init_Mem(string);
  188.    a=Init_Block(Start);
  189.    a|=PreCalc(Start,Konstanten);
  190.    printf("Es sind folgende Fehler aufgetreten : %ld\n",a);
  191.    
  192.    for(Zahl=0.0;Zahl<=3.141;Zahl+=.1)
  193.     {
  194.      Calc_P(&Zahl1,Start,&Zahl);
  195.      printf(">%s< x=%6.3lf %6.3lf\n",string,Zahl,Zahl1);
  196.     }
  197.    
  198.    Free_Block(Start);
  199.    Free_Konst(Konstanten);
  200.    
  201.    strcpy(string,"sin(x)+cos(x)");
  202.    Zahl=.345763;
  203.    
  204.    /* Alternative für wenige Rechnungen */
  205.    berechnen(&Zahl1,string,&Zahl,NULL,&a);
  206.    printf("Wert : %6.3lf Fehler %ld\n",Zahl1,a);
  207.    
  208.    
  209.    /* Auf Ende warten */
  210.    while(ENDE)
  211.     {
  212.      Wait(1L<<Window->UserPort->mp_SigBit);
  213.      /* Arbeitet ab, bis keine Events mehr */
  214.      while(EventAbfrage(Window,&msgInfo))
  215.       {
  216.        /* Verzweigt entsprechend der Events */
  217.        switch(msgInfo.NachrichtenArt)
  218.         {
  219.          case CLOSEWINDOW:ENDE=0;
  220.          break;
  221.          case GADGETDOWN:printf("Gadgetdown\n");
  222.         }
  223.       }
  224.     }
  225.    
  226.    CloseWindow(Window);
  227.    ende:
  228.    CloseLibrary(ToolBase);
  229.    CloseLibrary((struct Library *)GfxBase);
  230.    CloseLibrary((struct Library *)IntuitionBase);
  231.   }
  232.  
  233.